package daosimpl;

import model.Curso;
import model.Tematica;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Transaction;

import util.HibernateUtil;

import daos.TematicaDAO;

public class TematicaDAOImplH implements TematicaDAO {	
	private Transaction tx;

	@Override
	public Tematica FindByID(String id) throws HibernateException {
		Tematica result = new Tematica();
		try {
			
			tx = HibernateUtil.session.beginTransaction();
						
			Query query = HibernateUtil.session
					.createQuery("FROM Tematica where tematicaId = '"+
			id +"'");
			result = (Tematica) query.list().get(0);
			System.out.println(query.list());
			System.out.println(query.list().size());
			if (query.list().isEmpty()) {
				System.out.println("esta vacio");
			}
			tx.commit();
			if (!tx.wasCommitted()){
			    tx.commit();
			}			
			return result;
			
		} catch (Exception he) {
			System.out.println("mall " + he.getMessage() + he.getCause());
			tx.rollback(); 
		} finally { 
            //session.close(); 
        }  
		return result; 
	}


}
